package cn.itsource.basic.basic.service.impl;

import cn.itsource.basic.PageList;
import cn.itsource.basic.basic.mapper.BaseMapper;
import cn.itsource.basic.basic.query.BaseQuery;
import cn.itsource.basic.basic.service.IBaseService;
import cn.itsource.org.domain.Department;
import cn.itsource.org.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class IBaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;


    @Override
    @Transactional
    public void add(T t) {
        mapper.insert(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public T queryById(Long id) {
        return (T) mapper.selectById(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.selectAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long total = mapper.count();
        List<T> list = mapper.pageData(query);
        return new PageList<T>(total, list);
    }

    @Override
    @Transactional
    public void batchRemove(List<Long> ids) {
        mapper.batchRemove(ids);
    }
}
